# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/5 下午4:13
 @Author  : tgy
 
"""
import multiprocessing
import time
import os


datas = []


def run1():
    ...
    print(multiprocessing.current_process())
    print(os.getpid())
    print(os.getppid())
    # 杀死自己的父进程
    # os.kill(os.getppid(), 9)
    for i in range(10):
        print(i)
        time.sleep(0.5)
        datas.append(i)



def test01():
    ...
    print(multiprocessing.current_process())
    # 默认情况下父进程等待子进程结束完成，才结束，可以设置子进程为守护进程
    process = multiprocessing.Process(target=run1)
    process.daemon = True
    process.start()
    # join 等待调用方法的进程执行完成
    process.join()
    print('11111')
    # while process.is_alive():
    #     print(datas)
    #     time.sleep(1)



def run02(name,age):
    ...
    print(name,age,sep=':')


def test02():
    # 进程传递参数
    process = multiprocessing.Process(target=run02,args=('zhangsan',), kwargs={'age': 21})
    process.start()



if __name__ == '__main__':
    ...
    test02()
